package com.cdy.jxc_project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdy.jxc_project.domain.TCustomer;
import com.cdy.jxc_project.domain.vo.TCustomerVo;
import com.cdy.jxc_project.mapper.TCustomerMapper;
import com.cdy.jxc_project.service.TCustomerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/*
 * @Project:jxc_project
 * @Author:cdy(缘生)
 * @Motto:放下杂念,只为迎接明天更好的自己
 * @Date:2023/4/20 16:38
 * */
@Service
@Transactional
public class TCustomerServiceImpl extends ServiceImpl<TCustomerMapper,TCustomer>implements TCustomerService {

   @Resource
   private TCustomerMapper tCustomerMapper;

    @Override
    public Page<TCustomer> queryTCustomerPage(TCustomerVo tCustomerVo) {
        QueryWrapper<TCustomer> queryWrapper = new QueryWrapper<TCustomer>();
        queryWrapper.like("name",tCustomerVo.getName());
        queryWrapper.like("address",tCustomerVo.getAddress());

        Page<TCustomer> page = new Page(tCustomerVo.getCurrentPage(), tCustomerVo.getPageSize());
        return tCustomerMapper.selectPage(page, queryWrapper);

    }

    @Override
    public boolean deleteTCustomer(Integer id) {
        if (tCustomerMapper.deleteById(id)>0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public int insertTCustomer(TCustomer tCustomer) {
        return tCustomerMapper.insert(tCustomer);
    }

    @Override
    public int updateTCustomer(TCustomer tCustomer) {
        return tCustomerMapper.updateById(tCustomer);
    }
}
